// 登录接口模拟
import { MockMethod } from 'vite-plugin-mock'

const loginUserData = [
    {
        "id": 1,
        "username": "admin",
        "password": "admin",
        "age": 24,
        "role": "Role_admin",
        "addTime": new Date()
    },
    {
        "id": 2,
        "username": "fox",
        "password": "fox",
        "age": 18,
        "role": "Role_normal",
        "addTime": new Date()
    },
    {
        "id": 3,
        "username": "guest",
        "password": "guest",
        "age": 20,
        "role": "Role_normal",
        "addTime": new Date()
    }
]

// @ts-ignore
export default [
    {
        url: '/api/loginUser',
        method: 'post',
        timeout: 300,
        // @ts-ignore
        response: ({ body }:{body:any}) => {
            if (body){
                const index = loginUserData.findIndex(item => item.username === body.username && item.password === body.password)
                if (index > -1){
                    return {
                        code: 200,
                        mes: '登录成功!'
                    }
                }else {
                    return {
                        code: 300,
                        mes: '用户名或密码错误！'
                    }
                }
            }
            return {
                code: 100,
                mes: '登录失败，请稍后在试！'
            }}
    }
] as MockMethod[]
